import { Injectable } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Routes } from '@angular/router';
import { UserRouteAccessService } from 'app/core';
import { of } from 'rxjs';
import { map } from 'rxjs/operators';
import { ElecBicycleUser } from 'app/shared/model/elec-bicycle-user.model';
import { ElecBicycleUserService } from './elec-bicycle-user.service';
import { ElecBicycleUserComponent } from './elec-bicycle-user.component';
import { ElecBicycleUserDetailComponent } from './elec-bicycle-user-detail.component';
import { ElecBicycleUserUpdateComponent } from './elec-bicycle-user-update.component';
import { ElecBicycleUserDeletePopupComponent } from './elec-bicycle-user-delete-dialog.component';
import { IElecBicycleUser } from 'app/shared/model/elec-bicycle-user.model';

@Injectable({ providedIn: 'root' })
export class ElecBicycleUserResolve implements Resolve<IElecBicycleUser> {
    constructor(private service: ElecBicycleUserService) {}

    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        const id = route.params['id'] ? route.params['id'] : null;
        if (id) {
            return this.service.find(id).pipe(map((elecBicycleUser: HttpResponse<ElecBicycleUser>) => elecBicycleUser.body));
        }
        return of(new ElecBicycleUser());
    }
}

export const elecBicycleUserRoute: Routes = [
    {
        path: 'elec-bicycle-user',
        component: ElecBicycleUserComponent,
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.elecBicycleUser.home.title'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'elec-bicycle-user/:id/view',
        component: ElecBicycleUserDetailComponent,
        resolve: {
            elecBicycleUser: ElecBicycleUserResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.elecBicycleUser.home.title'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'elec-bicycle-user/new',
        component: ElecBicycleUserUpdateComponent,
        resolve: {
            elecBicycleUser: ElecBicycleUserResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.elecBicycleUser.home.title'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'elec-bicycle-user/:id/edit',
        component: ElecBicycleUserUpdateComponent,
        resolve: {
            elecBicycleUser: ElecBicycleUserResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.elecBicycleUser.home.title'
        },
        canActivate: [UserRouteAccessService]
    }
];

export const elecBicycleUserPopupRoute: Routes = [
    {
        path: 'elec-bicycle-user/:id/delete',
        component: ElecBicycleUserDeletePopupComponent,
        resolve: {
            elecBicycleUser: ElecBicycleUserResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.elecBicycleUser.home.title'
        },
        canActivate: [UserRouteAccessService],
        outlet: 'popup'
    }
];
